#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Node {
   public:
    int val;
    Node* next;
    Node* random;

    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
    bool hasNode(TreeNode* t, TreeNode* target) {
        if (t == NULL) return false;
        if (t == target) return true;
        return hasNode(t->left, target) || hasNode(t->right, target);
    }

   public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if (root == p || root == q) return root;
        bool lp = hasNode(root->left, p);
        bool lq = hasNode(root->left, q);
        bool rp = hasNode(root->right, p);
        bool rq = hasNode(root->right, q);
        if ((lp && rq) || (lq && rp)) return root;
        if (lp && lq) return lowestCommonAncestor(root->left, p, q);
        if (rp && rq) return lowestCommonAncestor(root->right, p, q);
        return NULL;
    }
};

int main() {
    cout << "Hello, World!";
    // Solution()
    return 0;
}
